package cn.itcast.bos_sms.consumer;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

//消费生产的消息  把消息中的内容也就是内容和验证码取出来 CustomerAction那边生产内容 这边获取
//利用第三方短信工具类发送短信
@Service("smsConsumer")
public class SmsConsumer implements MessageListener{
	@Override
	public void onMessage(Message message) {
		 MapMessage mapMessage = (MapMessage) message;
		// 调用SMS服务发送短信
			// String result = SmsUtils.sendSmsByHTTP(model.getTelephone(),msg);						 
			 try {
				 String telephone = mapMessage.getString("telephone");
				 String msgContent = mapMessage.getString("msgContent");
				 System.out.println("发送短信成功，手机号："+telephone+
							"验证码"+msgContent);
				 //如果返回值是以000开头说明发送成功过  否则发送失败
				 String result = "000/xxxx"; 
				 if(result.startsWith("000")){   //发送成功 return NONE;
					 System.out.println("发送短信成功，手机号："+telephone+"验证码"+msgContent);					 
				 }else{ 
					 throw new RuntimeException("短信发送失败,信息码"+result); 
			 }				
			} catch (Exception e) {
				e.printStackTrace();
			}
			 
			 
	}

	
}
